﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _5.原型模式
{
    class Program
    {
        static void Main(string[] args)
        {
            MonkeyPrototype prototypeMonkey = new ConcretePrototype("Monkey");
            MonkeyPrototype clone1 = prototypeMonkey.Clone() as ConcretePrototype;
            Console.WriteLine("克隆1：" + clone1.name);
            MonkeyPrototype clone2 = prototypeMonkey.Clone() as ConcretePrototype;
            Console.WriteLine("克隆2：" + clone2.name);
            Console.ReadLine();
        }
    }


    public abstract class MonkeyPrototype //孙悟空原型
    {
        public string name { get; set; }
        public MonkeyPrototype(string Name)
        {
            name = Name;
        }
        public abstract MonkeyPrototype Clone();
    }
    public class ConcretePrototype : MonkeyPrototype
    {
        public ConcretePrototype(string id) : base(id) { }
        public override MonkeyPrototype Clone()//浅拷贝
        {
            return (MonkeyPrototype)MemberwiseClone();//调用MemberwiseClone()的是浅拷贝
        }
    }
}
